package cn.guxinhu.billsystem.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Guxinhu
 * @create 2021-06-21 15:42
 */
@RestController
public class UserDeleteController {
    /**
     * @Description: 删除的控制层
     * @Method: DeleteContrller.delete()
     * @Param: /delete -- 网页映射路径
     * ids(Integer[]) -- 前端传入的数组
     * @Return:
     * @Author: Guxinhu
     * @Date Created in 2020/08/19 11:37
     */
    @Autowired
    private UserDeleteController userDeleteController;

    @RequestMapping("/user/delete")
    public String delete(String[] ids) {
        String mes = "成功";
        if (ids == null)
            return "操作失败";
        try {
            userDeleteController.delete(ids);
        } catch (Exception e) {
            DuplicateKeyException sqlException = e instanceof DuplicateKeyException ? ((DuplicateKeyException) e) : null;
            if (sqlException != null) {
                mes = "账号已存在";
            }
        }
        return mes;
    }
}
